package com.huike.controller.activity;


import com.huike.dto.ActivityDTO;
import com.huike.pojo.Activity;
import com.huike.pojo.Activity_Channel;
import com.huike.pojo.Activity_Status;
import com.huike.pojo.Activity_Vouchers;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.activity.ActivityService;
import com.huike.vo.ActivityVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.huike.result.Result.success;

@RestController
@RequestMapping()
@ApiOperation("活动管理")
public class ActivityController {


    @Autowired
    private ActivityService activityService;


    @GetMapping("/clues/activity/list")
    @ApiOperation("分页查询")
    public PageResult page(ActivityDTO dto){
        PageResult pageResult=activityService.page(dto);
        return pageResult;
    }

    @GetMapping("system/dict/data/type/clues_item")
    @ApiOperation("新增查询活动渠道")
    public Result findChannel(Activity_Channel channel){
       return activityService.findChannel(channel);
    }

    @GetMapping("/system/dict/data/type/channel_type")
    @ApiOperation("新增查询活动类型")
    public Result findVouchers(Activity_Vouchers vouchers){
        return activityService.findVouchers(vouchers);
    }

    @GetMapping("/system/dict/data/type/activity_status")
    @ApiOperation("新增查询活动状态")
    public Result findStatus(Activity_Status status){
        return activityService.findStatus(status);

    }

    @PostMapping("/clues/activity")
    @ApiOperation("新增活动")
    public Result save(@RequestBody Activity activity){
        return activityService.save(activity);
    }


    @DeleteMapping("clues/activity/{id}")
    @ApiOperation("删除活动")
    public Result delete(@PathVariable Long id){
        activityService.delete(id);
        Result<Object> success = success();
        success.setMsg("操作成功");
        return success();
    }

    @GetMapping("/clues/activity/{id}")
    @ApiOperation("根据id查活动")
    public Result findById(@PathVariable Long id){
       ActivityVO vo= activityService.findById(id);
       return Result.success(vo);
    }

    @PutMapping("/clues/activity")
    @ApiOperation("修改活动")
    public Result update(@RequestBody Activity activity){
        activityService.update(activity);
        return Result.success();
    }

}
